/**
 * Created by Administrator on 2017/7/3.
 */
var header=avalon.define({
    $id:'header'
})
var vm_index = avalon.define({
    $id: "index",
    bannerArr: [],
    columnContent: [],
    columnTitle: [],
    currentVedio: '',
    tnTab: function () {
        // var n = 0;
        $(".tnTab li").eq(0).addClass("active").siblings().removeClass("active")
        $(".tnTab li a").click(function () {
            n = $(".tnTab li a").index($(this));
            $(".tnTabContent").eq(n).addClass("current").siblings().removeClass("current");
            $(".tnTab li").eq(n).addClass("active").siblings().removeClass("active")
        })
    },
    autoplay: function () {
        setTimeout(function () {
            $('.single-item').slick({
                dots: true,
                autoplay: true,
                autoplaySpeed: 2000,
            });
        }, 300)
    },
    viewAudio: function (index) {
        /*var url=this.columnContent[4][index].url1 || this.columnContent[4][index].url2
         window.location.href = url;*/
        this.currentVedio = this.columnContent[4][index].url1 || this.columnContent[4][index].url2
    }
})
init();
var timeout=-1;
function init() {
    console.log("navListRight=="+navListRight);
    clearTimeout(timeout);
    timeout = setTimeout(function () {/*解决第一次进来common.js里面的pageId还没有缓存起来的问题*/
        if (navListRight) {
            getColumnId();
        } else {
            init();
        }
    }, 100);
}

function getColumnId() {
    var pageId = getPageId('公司简介');
    var ColumnIdArr = [];
    console.log('pageId=' + pageId);
    var _basePath = getCatelogUrl(pageId);
    console.log(_basePath);
    $.frontEngineAjax.ajaxRequest(function (data) {
        var tempOption;
        for (var i = 0, len = data.length; i < len; i++) {
            var name = conformName(data[i].name);
            tempOption = {
                "name": name,
                "number": data[i].number
            }
            ColumnIdArr[i] = tempOption;
        }
        console.log(ColumnIdArr);
        getColumnData(ColumnIdArr)
    }, _basePath)
}

var index = 0;
function getColumnData(ColumnIdArr) {
    var lenth = ColumnIdArr.length;
    console.log(lenth);
    if (index < lenth) {
        var _basePath = getDataUrl(ColumnIdArr[index].number);
        console.log("getColumnData _basePath=" + _basePath);
        $.frontEngineAjax.ajaxRequest(function (data) {
            if (index == 4) {
                vm_index.columnContent.push(data);
                vm_index.currentVedio = data[0].url1;
            } else {
                vm_index.columnContent.push(data[0]);
            }
            if (index == 0) {
                console.log('data[0].length = ' + data.length)
                for (var i = 0, len = data.length; i < len; i++) {
                    var tempImhUrl = data[i].imageUrl;
                    vm_index.bannerArr.push(spliceImgUrl(tempImhUrl));
                }
                console.log('vm_index.bannerArr=' + JSON.stringify(vm_index.bannerArr, null, 4))
            } else {
                var tempName = data[0].catelog.name;
                vm_index.columnTitle.push(conformName(tempName))
            }
            index++;
            getColumnData(ColumnIdArr);

        }, _basePath);
        console.log(JSON.stringify(vm_index.columnContent.length, null, 4))
    } else {
        return;
    }
}
